<template>
  <div id="background" type="center" class="row-bg" >

  <div>
  <el-header>
    <h1>欢迎来到MBTI人格测试</h1>
  </el-header>
  </div>

  <el-carousel :interval="4000" type="card" height="500px" ref="carousel">
    <el-carousel-item v-for="item in imagebox" :key="item.id">
      <router-link :to="item.pathUrl" tag="div">
        <div>
<!--      <img :src="item.idView" class="image" @click="tohome">-->
        <img :src="item.idView" class="image">
      <h3 text="2xl" justify="center">{{ item }}</h3>
        </div>
      </router-link>
    </el-carousel-item>
  </el-carousel>
<!--  </div>-->
  </div>
</template>

<script>

import Home from '../views/Home'
// import Role from '../views/sys/Role'
// import User from '../views/sys/User'
// import SideMenu from '../views/Home'
import QuestionPage from '../views/QuestionPage'
import Login from '../views/Login'

export default {
  name: "cardtest",
  components:{
    // User,
    // Role,
    Home,
    // SideMenu,
    QuestionPage,
    Login
  },
  data() {
    return {
      imagebox: [
        {id: 0, idView: require('../image/jellyfish.jpg'),pathUrl:"/SideMenu"},
        {id: 1, idView: require('../image/wall.jpg'),pathUrl: "/QuestionPage"},
        {id: 2, idView: require('../image/fox.jpg'),pathUrl: "/Home"},
        {id: 3, idView: require('../image/flower.jpg'),pathUrl: "/Login"}

        // {id: 0, idView: require('../image/jellyfish.jpg'),link:'/Menu'},
        // {id: 1, idView: require('../image/wall.jpg'),link: '/Role'},
        // {id: 2, idView: require('../image/fox.jpg'),link: '/User'},
        // {id: 3, idView: require('../image/flower.jpg'),link: '/SideMenu'}
      ],
      screenWidth: 0
    }
    },

     created()
    {
      console.log("主页面")
    },

  methods:{

    linkTo(){
        let activeIndex = this.$refs.carousel.activeIndex
      this.$router.push(this.imagebox[activeIndex].link)
    },


    setSize:function () {
      // 通过浏览器宽度(图片宽度)计算高度
      this.bannerHeight = 400 / 1920 * this.screenWidth;
    },
  },
  mounted() {
    // 首次加载时,需要调用一次
    this.screenWidth =  window.innerWidth;
    this.setSize();
    // 窗口大小发生改变时,调用一次
    window.onresize = () =>{
      this.screenWidth =  window.innerWidth;
      this.setSize();
    }
  },

  // beforeCreate () {
  //   this.$nextTick(()=>{
  //     document.body.setAttribute('style', 'background:#EAECF1')
  //   })
  // },
  // //实例销毁之前钩子--移除body 标签的属性style
  // beforeDestroy () {
  //   document.body.removeAttribute('style')
  // }

}

</script>

<style scoped>
.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

img{
  width: 1000px;
  height: 500px;
}

/*.item.active .shadow{*/
/*  background: linear-gradient(to top, rgb(0, 0, 14) 65%,transparent);*/
/*}*/


</style>
